﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YXQ.Common.Helper;
using YXQ.Dao.ViewModel;
using YXQ.Service;

namespace YXQ.Manager.Manager
{
    public partial class UserDetail : BaseAdminPage
    {
        UserModel model = new UserModel();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hfId.Value = reqID.ToString();
               
                GetUser();
            }

        }
        private void GetUser()
        {

            model = CenterService.userService.GetOneById(reqID);
            if (model != null)
            {

                //
                txtUserName.Value = model.UserName;
                drpUse.SelectedValue = model.Status.ToString();
                //
                //txtPwd.Value = model.Pwd;

                //
                txtTel.Value = model.Tel;

                //
                txtEmail.Value = model.Email; 

                //
                txtRealName.Value = model.RealName;

            }

        }



        /// <summary>
        /// 保存一条数据
        /// <summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {

            model = string.IsNullOrEmpty(hfId.Value)||hfId.Value=="0" ? new UserModel() : CenterService.userService.GetOneById(Convert.ToInt32(hfId.Value));
            //
            model.UserName = txtUserName.Value;

            if (string.IsNullOrEmpty(model.Pwd))
            {
                model.Pwd = StringUtils.EncryptPassWord("123456", StringUtils.PassFormat.MD5);
            }

            if (!string.IsNullOrEmpty(txtPwd.Value))
            {
                model.Pwd = StringUtils.EncryptPassWord(txtPwd.Value, StringUtils.PassFormat.MD5);
            }
           
            //
            model.Tel = txtTel.Value;

            //
            model.Email = txtEmail.Value;

            //
            model.CreateTime = DateTime.Now;

            //
            model.Status = Convert.ToInt32(drpUse.SelectedValue);


            //
            model.RealName = txtRealName.Value;

            if (CenterService.userService.Save(model) > 0)
            {

                JsHelper.AlertAndClose(this, "数据保存成功！");
            }

        }

    }
}
 